package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.UserDTO;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.query.UserQuery;
import com.feisuanyz.lyweb01.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "用户管理")
@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * register
     *
     * @param userDTO 用户注册入参实体类
     * @return
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @Operation(summary = "register")
    @ResponseBody
    public RestResult<Boolean> registerUser(@RequestBody @Validated(CreateGroup.class) UserDTO userDTO) {
        Boolean result = userService.registerUser(userDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * login
     *
     * @param userQuery 用户登录和密码找回入参实体类
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @Operation(summary = "login")
    @ResponseBody
    public RestResult<Boolean> loginUser(@RequestBody @Validated(QueryGroup.class) UserQuery userQuery) {
        Boolean result = userService.loginUser(userQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * recoverPassword
     *
     * @param userQuery 用户登录和密码找回入参实体类
     * @return
     */
    @RequestMapping(value = "/recoverPassword", method = RequestMethod.POST)
    @Operation(summary = "recoverPassword")
    @ResponseBody
    public RestResult<Boolean> recoverPassword(@RequestBody @Validated(QueryGroup.class) UserQuery userQuery) {
        Boolean result = userService.recoverPassword(userQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
